package com.qf.swagger2204.controller;

import com.qf.swagger2204.entity.User;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/user")
public class UserController {
//    @GetMapping("/get")
//    public User findById(Integer id) {
//
//        User user = new User();
//
//        user.setId(id);
//        user.setName("zhangsan");
//        user.setSex("1");
//
//        return user;
//    }
    //@RequestBody注解的作用，把请求体中的json转换为user对象
    //@RequestBody和@ResponseBody的区别
    //@ResponseBody返回的的数据
@PostMapping("/add")
public User addUser(@RequestBody User user) {
    System.out.println("====" + user);
    System.out.println("=====添加用户成功=====");
    return user;
}
@RequestMapping(value = "/test1",method = RequestMethod.GET)
public String test1(){
    System.out.println("test1....");
    return "hello swagger";
}
    @RequestMapping(value = "/test2",method = RequestMethod.POST)
    public User test2(){
        System.out.println("getUser....");
        User user = new User();
        user.setName("jack");
        user.setPassword("123");
        return user;
    }
    @GetMapping("/getUser/{id}")
    public User findById(@PathVariable(value = "id") Long id) {
        User user = new User();
        user.setId(1);
        user.setPassword("123");
        user.setName("张三");
        user.setRegistTime(new Date());
        user.setBirthday(new Date());
        user.setSex("1");
        return user;
    }
    @ApiOperation("测试2")
    @PostMapping("/test3")
    @ResponseBody
    public User test3( String name,
                       String password,
                       @RequestHeader("token") String token,
                       @RequestBody User user){
        System.out.println(name);
        System.out.println(password);
        System.out.println(token);
        User use1 = new User();
        user.setName("jack");
        user.setPassword("123");
        return use1;
    }
}
